import {defineStore} from "pinia";
import {getRoleById} from "@/api/api";
import router from "../router"
const routesArr=[
    {
      path:"password",
      component:()=>import("@/views/Password.vue"),
      meta:{
          label:"密码管理"
      }
    },
    {
      path:"customer",
      component:()=>import("@/views/Customer.vue"),
      meta:{
          label:"客户管理"
      }
    },
    {
      path:"role",
      component:()=>import("@/views/Role.vue"),
      meta:{
          label:"角色管理"
      }
    },
    {
      path:"manager",
      component:()=>import("@/views/Manager.vue"),
      meta:{
          label:"成员管理"
      }
    },
    {
      path:"contract",
      component:()=>import("@/views/Contract.vue"),
      meta:{
          label:"合同管理"
      }
    },
    {
      path:"menu",
      component:()=>import("@/views/Menu.vue"),
      meta:{
          label:"菜单管理"
      }
    },
  ];
export const useRouteStore = defineStore('routes', {
    state: () => ({ menu:[] as any }),
    actions: {
        addRoutes:async function(rid:number) {
            const role=await getRoleById(rid);
            this.menu=JSON.parse(role.data.data.menu);
            routesArr.forEach(v=>{
                if(this.menu.includes(v.meta.label)){
                    router.addRoute("main",v);
                }
            })
        }
    }
  })